import { Component, Output, Input, EventEmitter } from '@angular/core';
import { UtilService } from '../../../../../my-service/util.service';
@Component({
  selector: 'addbox-root',
  templateUrl: './addbox.component.html',
  styleUrls: ['./addbox.component.css']
})
export class addboxComponent {
  data = {
    Title: '',
    Content: '',
    name: '',
    PK_AnchorGuid:'',
    PK_BlockGuid:''
  }
  @Input() config: any;
  @Output() onok = new EventEmitter<Event>();
  @Output() oncancel = new EventEmitter<Event>();
  constructor(
    private UtilService: UtilService,
  ) { }

  ok(data) {
    this.data.PK_BlockGuid=this.config.PK_BlockGuid?this.config.PK_BlockGuid:''
    this.data.PK_AnchorGuid=this.config.PK_AnchorGuid;
    if (this.config.HaveTitle && !this.data.Title) {
      this.UtilService.remind('erroe', '标题不能为空')
      return
    }
    if (!this.data.Content) {
      this.UtilService.remind('erroe', '内容不能为空')
      return
    }
    if (this.config.HaveAuthor && !this.data.name) {
      this.UtilService.remind('erroe', '名字不能为空')
      return
    }
    this.onok.emit(data)
  }
  cancel() {
    this.oncancel.emit()
  }
}
